﻿/*
Copyright (c) 2011 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

#region Usings
using System.Collections.Generic;
using HaterAide.Cache.Interfaces;
using HaterAide.Interfaces;
using Utilities.SQL.DataClasses;

#endregion

namespace HaterAide.SQL.Interfaces
{
    /// <summary>
    /// SQL provider abstract class
    /// </summary>
    public abstract class IProvider
    {
        #region Public Properties

        /// <summary>
        /// Class manager
        /// </summary>
        public IClassManager ClassManager { get; set; }

        /// <summary>
        /// Settings manager
        /// </summary>
        public Settings.Settings Settings { get; set; }

        /// <summary>
        /// Mapping manager
        /// </summary>
        public IMappingManager MappingManager { get; set; }

        /// <summary>
        /// The connection string to the database
        /// </summary>
        public string ConnectionString { get; set; }

        /// <summary>
        /// Should this provider auto update?
        /// </summary>
        public bool Update { get; set; }

        /// <summary>
        /// Should this provider be writable?
        /// </summary>
        public bool Write { get; set; }

        /// <summary>
        /// Should this provider be readable?
        /// </summary>
        public bool Read { get; set; }

        /// <summary>
        /// The cache provider
        /// </summary>
        public abstract ICache Cache { get; set; }

        /// <summary>
        /// The database structure for this provider
        /// </summary>
        public Database Database { get; set; }

        #endregion

        #region public Abstract Functions

        /// <summary>
        /// Saves an object
        /// </summary>
        /// <param name="Object">Object to save</param>
        /// <param name="CurrentSession">Current session</param>
        /// <returns>True if it saved, false otherwise</returns>
        public abstract bool Save(object Object, Session CurrentSession);

        /// <summary>
        /// Deletes an object
        /// </summary>
        /// <param name="Object">Object to delete</param>
        /// <param name="CurrentSession">Current session</param>
        public abstract void Delete(object Object, Session CurrentSession);

        /// <summary>
        /// Creates the database and tables
        /// </summary>
        public abstract void Create();

        /// <summary>
        /// Selects an object based on ID
        /// </summary>
        /// <typeparam name="T">The type of the returned object</typeparam>
        /// <param name="IDValue">ID of the object</param>
        /// <param name="CurrentSession">Current session</param>
        /// <param name="Object">Object</param>
        /// <returns>The object specified</returns>
        public abstract T SelectByID<T>(object IDValue, Session CurrentSession, object Object);

        /// <summary>
        /// Selects a list of objects
        /// </summary>
        /// <typeparam name="T1">Input type</typeparam>
        /// <typeparam name="T2">Output type</typeparam>
        /// <param name="ID">ID of the input type</param>
        /// <param name="FieldName">The table name</param>
        /// <param name="CurrentSession">Current session</param>
        /// <returns>A list of objects associated with the object specified</returns>
        public abstract List<T2> SelectListByID<T1, T2>(object ID, string FieldName, Session CurrentSession);

        /// <summary>
        /// Selects all objects of a specific type
        /// </summary>
        /// <typeparam name="T">The type of the objects</typeparam>
        /// <param name="CurrentSession">Current session</param>
        /// <returns>A list of objects</returns>
        public abstract List<T> SelectAll<T>(Session CurrentSession);

        /// <summary>
        /// Selects a list of objects using a with and/or order by clause
        /// </summary>
        /// <typeparam name="T">The type of the returned value</typeparam>
        /// <param name="Clause">The where clause</param>
        /// <param name="OrderBy">The order by clause</param>
        /// <param name="CurrentSession">Current session</param>
        /// <param name="Start">Start position for paging</param>
        /// <param name="End">End position for paging</param>
        /// <returns>A list of objects meeting the criteria</returns>
        public abstract List<T> SelectWhere<T>(HaterAide.SQL.Interfaces.SQL.IClause<T> Clause, HaterAide.SQL.Interfaces.SQL.IClause<T> OrderBy, Session CurrentSession, int Start, int End);

        /// <summary>
        /// Selects a list of objects using a stored procedure defined by the user
        /// </summary>
        /// <typeparam name="T">The returned object type</typeparam>
        /// <param name="StoredProcedureName">The name of the stored procedure</param>
        /// <param name="Variables">A list of variables to be used by the stored procedure</param>
        /// <param name="CurrentSession">Current session</param>
        /// <returns>A list of objects</returns>
        public abstract List<T> SelectStoredProcedure<T>(string StoredProcedureName, List<HaterAide.SQL.Interfaces.SQL.IVariable> Variables, Session CurrentSession);

        /// <summary>
        /// Selects a list of objects using SQL text defined by the user
        /// </summary>
        /// <typeparam name="T">The returned object type</typeparam>
        /// <param name="SQLText">The SQL text</param>
        /// <param name="Variables">A list of variables to be used by the SQL text</param>
        /// <param name="CurrentSession">Current session</param>
        /// <returns>A list of objects</returns>
        public abstract List<T> SelectSQLText<T>(string SQLText, List<HaterAide.SQL.Interfaces.SQL.IVariable> Variables, Session CurrentSession);

        #endregion
    }
}
